package org.shj.book2.chapter09;

/**
 * Future 模式： 如果产生结果的操作比较耗时，我们可以先返回一个可以取得的结果的“票据”，主线程可以继续进行一些操作，然后再通过
 * “票据”获得结果.
 * 
 * @author huangjian
 *
 */
public class Main {

	public static void main(String[] args){
		System.out.println("main begin");
		Host host = new Host();
		//Data data1 = host.request(-1, 'A'); // 程序不能正确结束
		Data data1 = host.request(2, 'A'); 
		Data data2 = host.request(20, 'B');
		Data data3 = host.request(30, 'C');
		
		System.out.println("main otherJob Begin");
		
		try{
			Thread.sleep(2000);
		}catch(InterruptedException e){
			
		}
		
		System.out.println("main otherJob end");
		
		System.out.println("data1 = " + data1.getContent());
		System.out.println("data2 = " + data2.getContent());
		System.out.println("data3 = " + data3.getContent());
		
		System.out.println("main END");
		
	}
}
